package ab.mes.controller;


import ab.mes.entity.Orders;
import ab.mes.service.OrdersService;
import ab.mes.tools.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/orders")
public class OrdersController {
    @Autowired
    private OrdersService ordersService;

    //获取订单信息
    @PostMapping("/getOrders")
    public Result getOrders(){
        Result result=new Result();
        try {
            result = ordersService.getOrders();
        }catch (Exception e){
            result.setErrorMessage("查询订单失败！");
            e.printStackTrace();
        }
        return result;
    }

    //通过生产序号获取订单
    @PostMapping("/getOrdersByNumber")
    public Result getOrdersByNumber(String production_no){
        Result result=new Result();
        try {
            result = ordersService.getOrdersByNumber(production_no);
        }catch (Exception e){
            result.setErrorMessage("查询订单失败！");
            e.printStackTrace();
        }
        return result;
    }
    //新增订单信息
    @PostMapping("/insertOrders")
    public Result insertOrders(@RequestBody Orders orders){
        Result result=new Result();
        try {
            result = ordersService.insertOrders(orders);
        }catch (Exception e){
            result.setErrorMessage("新增订单失败！");
            e.printStackTrace();
        }
        return result;
    }
    //根据生产序号删除订单信息
    @PostMapping("/deleteOrders")
    public Result deleteOrders(Integer production_no){
        Result result = new Result();
        try{
            result = ordersService.deleteOrders(production_no);
        }catch (Exception e){
            result.setErrorMessage("删除订单失败！");
            e.printStackTrace();
        }
        return result;
    }
    //修改订单信息
    @PostMapping("/editOrders")
    public Result editOrders(@RequestBody Orders orders){
        Result result = new Result();
        try{
            result = ordersService.editOrders(orders);
        }catch (Exception e){
            result.setErrorMessage("修改订单失败！");
            e.printStackTrace();
        }
        return result;
    }

}
